<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>商家登录</title>
    <link href="../css/Hui.css" rel="stylesheet" type="text/css" />
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .checkbox-custom {
                @apply w-5 h-5 rounded border-neutral-300 text-primary focus:ring-primary transition duration-150 ease-in-out;
            }
            .btn-primary {
                @apply bg-primary hover:bg-primary/90 text-white font-medium py-3 px-6 rounded-lg transition-all duration-300 ease-in-out transform hover:scale-[1.02] active:scale-[0.98] disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:scale-100;
            }
            .link-primary {
                @apply text-primary hover:text-secondary transition-colors duration-200;
            }
            .form-input {
                @apply w-full px-4 py-3 rounded-lg border border-neutral-200 focus:border-primary focus:ring-2 focus:ring-primary/20 outline-none transition-all duration-200;
            }
        }
    </style>
    <style type="text/css">
        body { background: url(../image/login_bg.jpg) no-repeat left top; background-size: cover; }
    </style>
</head>
<body class="H-height-100-percent H-box-sizing-border-box H-overflow-hidden">
<div class="fix">
    <div class="H-horizontal-center H-padding-vertical-both-25">
        <div class="H-text-align-center">
            <img src="../image/logo.png" class="H-border-radius-12 H-margin-vertical-top-10" style="width:80px;height:80px;" />
            <div class="H-font-size-18">商家登录</div>
        </div>
    </div>

    <div class="H-border-vertical-top-after H-margin-vertical-top-10">
        <div class="H-flexbox-horizontal  H-border-vertical-bottom-margin-both-10-after">
                <span class="H-icon H-vertical-middle H-padding-horizontal-left-10">
                    <i class="H-iconfont H-icon-phone H-font-size-18 H-vertical-middle H-theme-font-color-999"></i></span>
            <input id="userId" type="text" class="H-textbox H-vertical-align-middle H-vertical-middle H-font-size-16 H-flex-item H-box-sizing-border-box H-border-none H-outline-none H-padding-15 H-theme-background-color-transparent" placeholder="请输入手机号码" />
        </div>
        <div class="H-flexbox-horizontal H-border-vertical-bottom-after">
                <span class="H-icon H-vertical-middle H-padding-horizontal-left-10">
                    <i class="H-iconfont H-icon-lock H-font-size-18 H-vertical-middle H-theme-font-color-999"></i></span>
            <input id="passWord" type="password" class="H-textbox H-vertical-align-middle H-vertical-middle H-font-size-16 H-flex-item H-box-sizing-border-box H-border-none H-outline-none H-padding-15 H-theme-background-color-transparent" placeholder="请输入登录密码" />
        </div>

        <!-- 协议勾选区域 -->
        <div class="H-padding-15">
            <div class="flex items-start space-x-3">
                <div class="flex items-center h-5" style="display: -webkit-inline-box;font-size: 14px;">
                    <input id="agreement" type="checkbox"  class="checkbox-custom" />
                    <div class="text-sm">
                        <label for="agreement" class="text-neutral-600">我已阅读并同意
                            <a href="/app/agreement" target="_blank" class="link-primary">《用户服务协议》</a>与<a href="/app/agreement" target="_blank" class="link-primary">《隐私政策》</a>
                        </label>
                        <p id="agreementError" class="text-red-500 mt-1 hidden">登录即代表认可全部内容</p>
                    </div>
                </div>

            </div>
        </div>

        <div class="H-padding-15 H-margin-vertical-top-5">
            <button class="H-button H-width-100-percent  H-font-size-15 H-outline-none
                H-padding-vertical-both-15 H-padding-horizontal-both-20 H-theme-background-color9
                H-theme-font-color-white H-theme-border-color9 H-theme-border-color9-click
                H-theme-background-color9-click H-theme-font-color9-click H-border-radius-3" id="loginBtn">登录</button>
        </div>
    </div>
</div>
<div class="H-padding-vertical-bottom-10"></div>

<script src="../script/H.js" type="text/javascript"></script>

<script src="../script/jquery-3.7.1.min.js" type="text/javascript"></script>
<script src="../script/md5.js" type="text/javascript"></script>
<script src="../api.js" type="text/javascript"></script>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script src="../miniprogram2h5.js" type="text/javascript"></script>

<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
<script>
    // VConsole 默认会挂载到 `window.VConsole` 上
    // var vConsole = new window.VConsole();
    // vConsole.hideSwitch(); // 隐藏开关
    // vConsole.hide(); // 确保面板关闭（若已打开）
</script>

<script type="text/javascript">
    $('#loginBtn').click(function () {
        login();
    });

    function login() {
        // 验证协议勾选
        // if (!$('#agreement').is(':checked')) {
        //     $('#agreementError').removeClass('hidden');
        //     return;
        // }

        var username = $('#userId').val();
        var password = $('#passWord').val();

        $.ajax({
            type : "post",
            url : '/app/loginV1',
            contentType:'application/json;charset=utf-8',
            dataType : "json",
            data : JSON.stringify({
                username: username,
                password: password
            }),
            async : true,
            success : function(json){
                if(json.code == 0){
                    var user = json.user;
                    var userId = json.user.userId;
                    debugger


                    sendToMiniProgram({
                        type: 'storeData',
                        data: password,
                        key : 'passwordxx'
                    });
                    localStorage.setItem('password', password);
                    localStorage.setItem("user", user);
                    localStorage.setItem("userId", userId);
                    localStorage.setItem("username", user.username);


                    sendToMiniProgram({
                        type: 'storeData',
                        data: user,
                        key : 'userInfo'
                    });


                    if(userId === 1){
                        H.openWin('table_head', '/app/adminindex');
                    }else{
                        H.openWin('table_head', '/app/merchantindex');
                    }
                }else{
                    alert(json.msg);
                }
            },
        });
    }

    // 监听协议勾选变化
    $('#agreement').change(function() {
        if ($(this).is(':checked')) {
            $('#agreementError').addClass('hidden');
        }
    });
</script>
</body>
</html>